package com.demo.provider;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;

import javax.jms.*;

/**
 * Created by HYZ on 2018/1/26.
 */
@Component
public class ProducerServiceImpl implements ProducerService{

    private Logger logger = LoggerFactory.getLogger(ProducerServiceImpl.class);

    @Autowired
    private JmsTemplate jmsTemplate;

    @Autowired Destination responseQueue;

    @Override
    public void sendMessage(Destination destination, final String message) {
        logger.info("生产者发送消息");
        logger.info("生产者发送来了一个消息,{}" , message);
        jmsTemplate.send(destination, new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                TextMessage textMessage = session.createTextMessage(message);
                //指定该消息对应的回复消息的目的地
                //textMessage.setJMSReplyTo(responseQueue);
                return textMessage;
            }
        });
    }
}
